// PropertyCustomVisitor.cpp: implementation of the PropertyCustomVisitor class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "PropertyCustomVisitor.h"
#include "PropertyComboWindow.h"
#include "PropertyTextWindow.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

PropertyCustomVisitor::PropertyCustomVisitor()
{

}

PropertyCustomVisitor::~PropertyCustomVisitor()
{
	for(int i = 0; i < m_theSubWindows.GetSize(); i++)
	{
		delete m_theSubWindows.GetAt(i);
	}
}

BOOL PropertyCustomVisitor::Visit(CustomDBVariable* pVar)
{
	if(pVar->IsComboBox())
	{
		PropertyComboWindow* pCombo = new PropertyComboWindow;
		pCombo->customVariable(pVar);
		AddSubWindow(pCombo);
	}
	else
	{
		PropertyTextWindow* pText = new PropertyTextWindow;
		pText->customVariable(pVar);
		AddSubWindow(pText);
	}
//	ASSERT(FALSE);
	return TRUE;
}

BOOL PropertyCustomVisitor::Visit(CustomNonDBVariable* pVar)
{
	if(pVar->IsComboBox())
	{
	}
	else
	{
		PropertyTextWindow* pText = new PropertyTextWindow;
		pText->customVariable(pVar);
		AddSubWindow(pText);
	}

	return TRUE;
}

BOOL PropertyCustomVisitor::Visit(DBVariable* pVar)
{
	return TRUE;
}

BOOL PropertyCustomVisitor::Visit(NonDBVariable* pVar)
{
	return TRUE;
}

void PropertyCustomVisitor::AddSubWindow(PropertySubWindow* pSubWnd)
{
	ASSERT(pSubWnd);

	PropertySubWindow* pTemp = NULL;
	PropertySubWindow* pInsertWnd = pSubWnd;
	for(int i = 0; i < m_theSubWindows.GetSize(); i++)
	{
		pTemp = m_theSubWindows.GetAt(i);
		if(pSubWnd->customVariable()->ArrangePrior() < pTemp->customVariable()->ArrangePrior())
		{
			m_theSubWindows.InsertAt(i, pSubWnd);
			return;
		}
	}
	m_theSubWindows.Add(pInsertWnd);
}